<?php
/**
 * 文件名brandslide.mod.php
 * 版本号：1.0
 * 作者：zhangbaofeng  2012-03-29
 * 功能描述: 品牌首页幻灯片
 */

if(!defined('IN_JISHIGOU'))
{
    exit('invalid request');
}

class ModuleObject extends MasterObject
{
	var $TopicLogic;	

	function ModuleObject($config)
	{
		$this->MasterObject($config);
		
		Load::logic('topic');
		$this->TopicLogic = new TopicLogic($this);
		
		Load::lib('form');
		$this->FormHandler = new FormHandler;
		
		$this->CacheConfig = ConfigHandler::get('cache');
		
		
		$this->Execute();
	}

	
	function Execute()
	{
		ob_start();
		switch($this->Code)
		{	
			case 'delete':
				$this->Delete();
				break;			
			case 'add':
				$this->Add();
				break;
			case 'modify':
				$this->Modify();
				break;
		   case 'domodify':
				$this->DoModify();
				break;
			default:
				$this->Main();
				break;
		}
		$body = ob_get_clean();
		
		$this->ShowBody($body);
		
	}

	
	function Main()
	{ 
	    $sql = "select * from `".TABLE_PREFIX."slide` ";
	 	$query = $this->DatabaseHandler->Query($sql);
	    $brandslide_list=array();
		while($row = $query->GetRow())
		{	
			$brandslide_list[]=$row;
		}
		$sl = count($brandslide_list);
		//die('pinpai');
		include($this->TemplateHandler->Template('admin/brandslide'));
	}

	function Add()
	{		
		//$pic = $this->Post['pic'];
		if($image=$_FILES['pic']['name']){
		  $filename = date('YmdHis');
		  $savename=$filename.strtolower(strstr($_FILES['pic']['name'], '.'));
		  $s_pic= dirname(dirname(dirname(__FILE__)))."/images/brand/".$savename;
		  if(is_uploaded_file($_FILES['pic']['tmp_name'])){
             if(!move_uploaded_file($_FILES['pic']['tmp_name'], $s_pic)){
             echo '移动文件失败！';
              exit;
          }
         }else{
           echo 'problem!';
           exit;
         }
		 }
		$sord = !empty($this->Post['sord'])?intval($this->Post['sord']):3;
		$addTime = time();
	    $sql = "insert into `".TABLE_PREFIX."slide` values ('','{$savename}','{$sord}')";
		$this->DatabaseHandler->Query($sql);
       	$this->Messager("添加成功",'admin.php?mod=brandslide');
	}
	
	function Modify()
	{ 
		$ids = (int) $this->Get['ids'];
		
		$action = "admin.php?mod=user_tag&code=domodify";
		
		$sql = "select * from `".TABLE_PREFIX."user_tag` where `id` = '{$ids}' ";
	 	$query = $this->DatabaseHandler->Query($sql);
	  $taglist=$query->GetRow();
	  
		include $this->TemplateHandler->Template('admin/user_tag_info');
	}
	
	function DoModify()
	{
		$tagid = (int) $this->Post['tagid'];
		$tagname = strip_tags($this->Post['tagname']);
		
		$sql = "select * from `".TABLE_PREFIX."user_tag` where `name` = '{$tagname}' ";
	 	$query = $this->DatabaseHandler->Query($sql);
	  $taglist=$query->GetRow();
	  
		if($taglist)
		{
			$this->Messager("{$tagname} 标签已经存在",-1);
		}
		
		$sql = "update `".TABLE_PREFIX."user_tag` set  `name` = '{$tagname}'  where `id`=".$tagid;	
		$this->DatabaseHandler->Query($sql);	
		
		$this->Messager("编辑成功",'admin.php?mod=user_tag');
	}
	
	function Delete()
	{
		$ids = (array) ($this->Post['ids'] ? $this->Post['ids'] : $this->Get['ids']);
		$media_count = count($ids);
		if(!$ids) {
			$this->Messager("请指定要删除的对象");
		}
		
		$sql = "delete from `".TABLE_PREFIX."slide` where `id` in(".implode(",",$ids).")";
		$this->DatabaseHandler->Query($sql);			
	    $this->Messager($return ? $return : "删除成功");
		
	}

}

?>
